Setup PostMan Mock Server
Postman Mocking
Mock servers simulate an API by returning predefined data, enabling you to develop or test against an API before it's production-ready (or without using production data). In Postman, mock servers rely on examples saved in a collection to return mock data.
Creating Mock Server
You can create mock servers from an existing collection, or Postman will create a new collection for your mock server. You can create a new mock from scratch, from a collection, from the New button, from an API, or from your history. Let's start creating a mock server from scratch. In Mock Servers on the left of Postman, click the + button.
Select an existing collection or add a new one (adding an initial request for a new one).
Configure Mock Details
When you create a mock server you will give it a name, choose a release tag, choose an optional environment to run the mock against, and configure a delay before the server sends your mock responses. If you choose to make your mock server private, you will need to add a Postman API key in the request header: x-api-key:<Your-Postman-API-key>
.
Select an existing collection or add a new one.
You can also opt to save the mock URL to an environment variable which you can then reference in your requests by making the environment active before sending.
Next, create a new request by selecting + or by selecting New > HTTP Request. Paste the mock URL into the new request and select Send.
Mock Call Logs
You can view and search the details of calls to your mock servers using the mock call log. Open a mock from Mock Servers on the left of Postman. Your mock overview and call log will open.
The mock call log lists an overview of calls made to the mock url, together with request and response details you can drill down into. Mock call log entries indicate the time a request was sent, the request method and path, and a response overview. Click an entry to see more detail on request headers and body, or response headers and body. Use the search field to find particular calls, and the refresh button at the top of the list to view up to date requests.